<!DOCTYPE html>
<html lang="zh-CN">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
        <link rel="stylesheet" type="text/css" href="../css/bootstrap.css">
        <script type="text/javascript" src="../js/bootstrap.bundle.js"></script>
        <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    </head>
    <body>
        <div class="form">
            <form>
                <div class="mb-3">
                    <label for="InputUserName" class="form-label">用户名</label>
                    <input class="form-control" id="InputUserName" placeholder="请输入用户名">
                </div>
                <div class="mb-3">
                    <label for="InputPassword" class="form-label">密码</label>
                    <input type="password" class="form-control" id="InputPassword" placeholder="请输入密码">
                </div>
                <button type="button" id="register_button" class="btn btn-primary">点击注册</button>
            </form>
        </div>

    <script>

        let username;
        let password;
        const register_button = document.querySelector("#register_button");
        register_button.addEventListener('click', function(e){
            username = document.querySelector("#InputUserName").value;
            password = document.querySelector("#InputPassword").value;
            axios({
                url:"https://hmajax.itheima.net/api/register",
                method: "post",
                data: {
                    username,
                    password
                }
            }).then(result => {
                alert(result.data.message);
                
            }).catch(error => {
                alert(error.response.data.message);
            });
        })
    </script>
    </body>
    <style>
        .form {
            width: 400px;
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
        }
    </style>
</html>